
**************** This program generates the results in Table 5 of the paper: heterogenous effects by similarity of respondent and second degree link **********

clear all
set more off, permanently
cd "$localdir\Data"
global output "$localdir\Output"





***************************************************** ASSESSMENT OF NATIONAL UNEMPLOYMENT RATE ******************************************************

* Outcome only available in 2011 and 2012

use "National Unemployment RF for Analysis - Last Year.dta", clear

* i industry
merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

* k industry
rename unique unique_i
rename ind_year_2 ind_year_2_i
rename unique_network unique

merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

rename ind_year_2 ind_year_2_network
rename unique unique_network 
rename unique_i unique 
rename ind_year_2_i ind_year_2 

g samegroup_ind=0 if ind_year_2!=ind_year_2_network
replace samegroup_ind=1 if ind_year_2==ind_year_2_network
tab year samegroup_ind, row

* i occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_i
rename ocp_year_1 ocp_year_1_i
rename unique_network unique 

* k occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_network
rename ocp_year_1 ocp_year_1_network
rename unique_i unique
rename ocp_year_1_i ocp_year_1

g samegroup_ocp=0 if ocp_year_1!=ocp_year_1_network
replace samegroup_ocp=1 if ocp_year_1==ocp_year_1_network
tab year samegroup_ocp, row

* Same industry OR occupation
g samegroup=0 if (samegroup_ind==0 & samegroup_ocp==0) & samegroup_ind!=. & samegroup_ocp!=.
replace samegroup=1 if (samegroup_ind==1 | samegroup_ocp==1) & samegroup_ind!=. & samegroup_ocp!=.
tab year samegroup, row

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen samegroup_share=mean(samegroup)
drop *_network
duplicates drop unique year, force

g unemp_samegroup_share=grossunemp_enter_network_share*samegroup_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var samegroup_share "Same industry (network share)"
lab var unemp_samegroup_share "Unemployment shock x Same industry"

replace unemp_rate_estimate=unemp_rate_estimate/100

* Results
display c(current_time)
reghdfe unemp_rate_estimate grossunemp_enter_network_share samegroup_share unemp_samegroup_share, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum unemp_rate_estimate if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum samegroup_share if e(sample)==1
local mean_same=r(mean)
local sd_same=r(sd)
outreg2 using "$output\Table5.xls", replace nocons nor ctitle("Guess national unemployment rate") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share samegroup_share unemp_samegroup_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Same industry mean,`mean_same', Same industry sd,`sd_same')

display c(current_time)









***************************************************** FORECAST OF NATIONAL UNEMPLOYMENT RATE ******************************************************

* Outcome only available in 2011

use "National Unemployment Forecast RF for Analysis - Last Year.dta", clear

* i industry
merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

* k industry
rename unique unique_i
rename ind_year_2 ind_year_2_i
rename unique_network unique

merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

rename ind_year_2 ind_year_2_network
rename unique unique_network 
rename unique_i unique 
rename ind_year_2_i ind_year_2 

g samegroup_ind=0 if ind_year_2!=ind_year_2_network
replace samegroup_ind=1 if ind_year_2==ind_year_2_network
tab year samegroup_ind, row

* i occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_i
rename ocp_year_1 ocp_year_1_i
rename unique_network unique 

* k occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_network
rename ocp_year_1 ocp_year_1_network
rename unique_i unique
rename ocp_year_1_i ocp_year_1

g samegroup_ocp=0 if ocp_year_1!=ocp_year_1_network
replace samegroup_ocp=1 if ocp_year_1==ocp_year_1_network
tab year samegroup_ocp, row

* Same industry OR occupation
g samegroup=0 if (samegroup_ind==0 & samegroup_ocp==0) & samegroup_ind!=. & samegroup_ocp!=.
replace samegroup=1 if (samegroup_ind==1 | samegroup_ocp==1) & samegroup_ind!=. & samegroup_ocp!=.
tab year samegroup, row

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen samegroup_share=mean(samegroup)
drop *_network
duplicates drop unique year, force

g unemp_samegroup_share=grossunemp_enter_network_share*samegroup_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var samegroup_share "Same industry (network share)"
lab var unemp_samegroup_share "Unemployment shock x Same industry"

replace unemp_rate_estimate_next=unemp_rate_estimate_next/100

* Results
display c(current_time)
reghdfe unemp_rate_estimate_next grossunemp_enter_network_share samegroup_share unemp_samegroup_share, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum unemp_rate_estimate_next if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum samegroup_share if e(sample)==1
local mean_same=r(mean)
local sd_same=r(sd)
outreg2 using "$output\Table5.xls", append nocons nor ctitle("National unemployment rate expectation") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share samegroup_share unemp_samegroup_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Same industry mean,`mean_same', Same industry sd,`sd_same')

display c(current_time)




***************************************************** UNEMPLOYMENT OUTCOMES - PROBABILITY ******************************************************

use "Unemployment Outcomes RF for Analysis - Last Year.dta", clear

* i industry
merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

* k industry
rename unique unique_i
rename ind_year_2 ind_year_2_i
rename unique_network unique

merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

rename ind_year_2 ind_year_2_network
rename unique unique_network 
rename unique_i unique 
rename ind_year_2_i ind_year_2 

g samegroup_ind=0 if ind_year_2!=ind_year_2_network
replace samegroup_ind=1 if ind_year_2==ind_year_2_network
tab year samegroup_ind, row

* i occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_i
rename ocp_year_1 ocp_year_1_i
rename unique_network unique 

* k occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_network
rename ocp_year_1 ocp_year_1_network
rename unique_i unique
rename ocp_year_1_i ocp_year_1

g samegroup_ocp=0 if ocp_year_1!=ocp_year_1_network
replace samegroup_ocp=1 if ocp_year_1==ocp_year_1_network
tab year samegroup_ocp, row

* Same industry OR occupation
g samegroup=0 if (samegroup_ind==0 & samegroup_ocp==0) & samegroup_ind!=. & samegroup_ocp!=.
replace samegroup=1 if (samegroup_ind==1 | samegroup_ocp==1) & samegroup_ind!=. & samegroup_ocp!=.
tab year samegroup, row

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen samegroup_share=mean(samegroup)
drop *_network
duplicates drop unique year, force

g unemp_samegroup_share=grossunemp_enter_network_share*samegroup_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var samegroup_share "Same industry (network share)"
lab var unemp_samegroup_share "Unemployment shock x Same industry"

replace prob_unemployed=prob_unemployed/100

* Results
display c(current_time)
reghdfe prob_unemployed grossunemp_enter_network_share samegroup_share unemp_samegroup_share, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum prob_unemployed if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum samegroup_share if e(sample)==1
local mean_same=r(mean)
local sd_same=r(sd)
outreg2 using "$output\Table5.xls", append nocons nor ctitle("Own unemployment expectation") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share samegroup_share unemp_samegroup_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Same industry mean,`mean_same', Same industry sd,`sd_same')

display c(current_time)














***************************************************** UNEMPLOYMENT OUTCOMES - UI POLICY ******************************************************

use "UI Outcomes RF for Analysis - Last Year.dta", clear

* i industry
merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

* k industry
rename unique unique_i
rename ind_year_2 ind_year_2_i
rename unique_network unique

merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

rename ind_year_2 ind_year_2_network
rename unique unique_network 
rename unique_i unique 
rename ind_year_2_i ind_year_2 

g samegroup_ind=0 if ind_year_2!=ind_year_2_network
replace samegroup_ind=1 if ind_year_2==ind_year_2_network
tab year samegroup_ind, row

* i occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_i
rename ocp_year_1 ocp_year_1_i
rename unique_network unique 

* k occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_network
rename ocp_year_1 ocp_year_1_network
rename unique_i unique
rename ocp_year_1_i ocp_year_1

g samegroup_ocp=0 if ocp_year_1!=ocp_year_1_network
replace samegroup_ocp=1 if ocp_year_1==ocp_year_1_network
tab year samegroup_ocp, row

* Same industry OR occupation
g samegroup=0 if (samegroup_ind==0 & samegroup_ocp==0) & samegroup_ind!=. & samegroup_ocp!=.
replace samegroup=1 if (samegroup_ind==1 | samegroup_ocp==1) & samegroup_ind!=. & samegroup_ocp!=.
tab year samegroup, row

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen samegroup_share=mean(samegroup)
drop *_network
duplicates drop unique year, force

g unemp_samegroup_share=grossunemp_enter_network_share*samegroup_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var samegroup_share "Same industry (network share)"
lab var unemp_samegroup_share "Unemployment shock x Same industry"

* Results
display c(current_time)
reghdfe more_ui grossunemp_enter_network_share samegroup_share unemp_samegroup_share, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum more_ui if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum samegroup_share if e(sample)==1
local mean_same=r(mean)
local sd_same=r(sd)
outreg2 using "$output\Table5.xls", append nocons nor ctitle("Want more unemployment insurance") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share samegroup_share unemp_samegroup_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Same industry mean,`mean_same', Same industry sd,`sd_same')

display c(current_time)








***************************************************** IDEOLOGY OUTCOMES ******************************************************

use "Ideology RF for Analysis - Last Year.dta", clear

* i industry
merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

* k industry
rename unique unique_i
rename ind_year_2 ind_year_2_i
rename unique_network unique

merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

rename ind_year_2 ind_year_2_network
rename unique unique_network 
rename unique_i unique 
rename ind_year_2_i ind_year_2 

g samegroup_ind=0 if ind_year_2!=ind_year_2_network
replace samegroup_ind=1 if ind_year_2==ind_year_2_network
tab year samegroup_ind, row

* i occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_i
rename ocp_year_1 ocp_year_1_i
rename unique_network unique 

* k occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_network
rename ocp_year_1 ocp_year_1_network
rename unique_i unique
rename ocp_year_1_i ocp_year_1

g samegroup_ocp=0 if ocp_year_1!=ocp_year_1_network
replace samegroup_ocp=1 if ocp_year_1==ocp_year_1_network
tab year samegroup_ocp, row

* Same industry OR occupation
g samegroup=0 if (samegroup_ind==0 & samegroup_ocp==0) & samegroup_ind!=. & samegroup_ocp!=.
replace samegroup=1 if (samegroup_ind==1 | samegroup_ocp==1) & samegroup_ind!=. & samegroup_ocp!=.
tab year samegroup, row

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen samegroup_share=mean(samegroup)
drop *_network
duplicates drop unique year, force

g unemp_samegroup_share=grossunemp_enter_network_share*samegroup_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var samegroup_share "Same industry (network share)"
lab var unemp_samegroup_share "Unemployment shock x Same industry"

* Results
display c(current_time)
reghdfe govt_more_help grossunemp_enter_network_share samegroup_share unemp_samegroup_share, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum govt_more_help if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum samegroup_share if e(sample)==1
local mean_same=r(mean)
local sd_same=r(sd)
outreg2 using "$output\Table5.xls", append nocons nor ctitle("Government should support the poor") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share samegroup_share unemp_samegroup_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Same industry mean,`mean_same', Same industry sd,`sd_same')

display c(current_time)











***************************************************** ECONOMIC POLICY ******************************************************

* These questions were not asked in 2012

use "Economic Policy Outcomes RF for Analysis - Last Year.dta", clear

* i industry
merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

* k industry
rename unique unique_i
rename ind_year_2 ind_year_2_i
rename unique_network unique

merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

rename ind_year_2 ind_year_2_network
rename unique unique_network 
rename unique_i unique 
rename ind_year_2_i ind_year_2 

g samegroup_ind=0 if ind_year_2!=ind_year_2_network
replace samegroup_ind=1 if ind_year_2==ind_year_2_network
tab year samegroup_ind, row

* i occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_i
rename ocp_year_1 ocp_year_1_i
rename unique_network unique 

* k occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_network
rename ocp_year_1 ocp_year_1_network
rename unique_i unique
rename ocp_year_1_i ocp_year_1

g samegroup_ocp=0 if ocp_year_1!=ocp_year_1_network
replace samegroup_ocp=1 if ocp_year_1==ocp_year_1_network
tab year samegroup_ocp, row

* Same industry OR occupation
g samegroup=0 if (samegroup_ind==0 & samegroup_ocp==0) & samegroup_ind!=. & samegroup_ocp!=.
replace samegroup=1 if (samegroup_ind==1 | samegroup_ocp==1) & samegroup_ind!=. & samegroup_ocp!=.
tab year samegroup, row

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen samegroup_share=mean(samegroup)
drop *_network
duplicates drop unique year, force

g unemp_samegroup_share=grossunemp_enter_network_share*samegroup_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var samegroup_share "Same industry (network share)"
lab var unemp_samegroup_share "Unemployment shock x Same industry"

* Results
display c(current_time)
reghdfe gov_solution grossunemp_enter_network_share samegroup_share unemp_samegroup_share, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum gov_solution if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum samegroup_share if e(sample)==1
local mean_same=r(mean)
local sd_same=r(sd)
outreg2 using "$output\Table5.xls", append nocons nor ctitle("Support non-market-based stimulus") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share samegroup_share unemp_samegroup_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Same industry mean,`mean_same', Same industry sd,`sd_same')

display c(current_time)








***************************************************** VOTING LEFT (INTENTION) ******************************************************

use "Voting RF for Analysis - Last Year.dta", clear

* i industry
merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

* k industry
rename unique unique_i
rename ind_year_2 ind_year_2_i
rename unique_network unique

merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

rename ind_year_2 ind_year_2_network
rename unique unique_network 
rename unique_i unique 
rename ind_year_2_i ind_year_2 

g samegroup_ind=0 if ind_year_2!=ind_year_2_network
replace samegroup_ind=1 if ind_year_2==ind_year_2_network
tab year samegroup_ind, row

* i occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_i
rename ocp_year_1 ocp_year_1_i
rename unique_network unique 

* k occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_network
rename ocp_year_1 ocp_year_1_network
rename unique_i unique
rename ocp_year_1_i ocp_year_1

g samegroup_ocp=0 if ocp_year_1!=ocp_year_1_network
replace samegroup_ocp=1 if ocp_year_1==ocp_year_1_network
tab year samegroup_ocp, row

* Same industry OR occupation
g samegroup=0 if (samegroup_ind==0 & samegroup_ocp==0) & samegroup_ind!=. & samegroup_ocp!=.
replace samegroup=1 if (samegroup_ind==1 | samegroup_ocp==1) & samegroup_ind!=. & samegroup_ocp!=.
tab year samegroup, row

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen samegroup_share=mean(samegroup)
drop *_network
duplicates drop unique year, force

g unemp_samegroup_share=grossunemp_enter_network_share*samegroup_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var samegroup_share "Same industry (network share)"
lab var unemp_samegroup_share "Unemployment shock x Same industry"

* Results
display c(current_time)
reghdfe vote_left grossunemp_enter_network_share samegroup_share unemp_samegroup_share, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum vote_left if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum samegroup_share if e(sample)==1
local mean_same=r(mean)
local sd_same=r(sd)
outreg2 using "$output\Table5.xls", append nocons nor ctitle("Intend to vote for left party") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share samegroup_share unemp_samegroup_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Same industry mean,`mean_same', Same industry sd,`sd_same')

display c(current_time)











***************************************************** VOTED LEFT ******************************************************

* These questions were only asked in 2011 - ie the year before which the shocks definitely occurred before the election

use "Voted RF for Analysis - Last Year.dta", clear

* i industry
merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

* k industry
rename unique unique_i
rename ind_year_2 ind_year_2_i
rename unique_network unique

merge m:1 unique year using "Industry codes.dta", keepusing(ind_year_2)
drop if _merge==2
drop _merge 

rename ind_year_2 ind_year_2_network
rename unique unique_network 
rename unique_i unique 
rename ind_year_2_i ind_year_2 

g samegroup_ind=0 if ind_year_2!=ind_year_2_network
replace samegroup_ind=1 if ind_year_2==ind_year_2_network
tab year samegroup_ind, row

* i occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_i
rename ocp_year_1 ocp_year_1_i
rename unique_network unique 

* k occupation
merge m:1 unique year using "Occupation codes.dta", keepusing(ocp_year_1)
drop if _merge==2
drop _merge 

rename unique unique_network
rename ocp_year_1 ocp_year_1_network
rename unique_i unique
rename ocp_year_1_i ocp_year_1

g samegroup_ocp=0 if ocp_year_1!=ocp_year_1_network
replace samegroup_ocp=1 if ocp_year_1==ocp_year_1_network
tab year samegroup_ocp, row

* Same industry OR occupation
g samegroup=0 if (samegroup_ind==0 & samegroup_ocp==0) & samegroup_ind!=. & samegroup_ocp!=.
replace samegroup=1 if (samegroup_ind==1 | samegroup_ocp==1) & samegroup_ind!=. & samegroup_ocp!=.
tab year samegroup, row

bysort unique year: egen grossunemp_enter_network_share=mean(grossunemp_enter_network)
bysort unique year: egen samegroup_share=mean(samegroup)
drop *_network
duplicates drop unique year, force

g unemp_samegroup_share=grossunemp_enter_network_share*samegroup_share

tab year 

lab var grossunemp_enter_network_share "Unemployment shock (network share)"
lab var samegroup_share "Same industry (network share)"
lab var unemp_samegroup_share "Unemployment shock x Same industry"

* Results
display c(current_time)
reghdfe voted_left_2011 grossunemp_enter_network_share samegroup_share unemp_samegroup_share, absorb(both ind2_year ocp_year educ_year) cluster(muni)
sum voted_left_2011 if e(sample)==1
local mean_outcome=r(mean)
local sd_outcome=r(sd)
sum grossunemp_enter_network_share if e(sample)==1
local mean_shock=r(mean)
local sd_shock=r(sd)
sum samegroup_share if e(sample)==1
local mean_same=r(mean)
local sd_same=r(sd)
outreg2 using "$output\Table5.xls", append nocons nor ctitle("Voted for left party in 2001") bdec(3) sdec(3) adec(3) label keep(grossunemp_enter_network_share samegroup_share unemp_samegroup_share) ///
adds(Outcome mean,`mean_outcome', Outcome sd,`sd_outcome', Unemployment shock mean,`mean_shock',  Unemployment shock sd,`sd_shock', Same industry mean,`mean_same', Same industry sd,`sd_same')

display c(current_time)









































